package com.qriver.distributed.transaction.service;


import com.qriver.distributed.transaction.entity.first.FirstEntity;
import com.qriver.distributed.transaction.entity.second.SecondEntity;
import com.qriver.distributed.transaction.mapper.first.FirstMapper;
import com.qriver.distributed.transaction.mapper.second.SecondMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class DemoTestService {

    @Autowired
    private FirstMapper firstMapper;

    @Autowired
    private SecondMapper secondMapper;

    @Transactional(transactionManager = "jtaTransaction")
    public void insertData(){
        //插入first
        FirstEntity firstEntity = new FirstEntity();
        firstEntity.setId(1);
        firstEntity.setName("test");
        firstMapper.insert(firstEntity);
        //插入second
        SecondEntity secondEntity = new SecondEntity();
        secondEntity.setId(1);
        secondEntity.setName("test2");
        secondMapper.insert(secondEntity);
    }

}
